package io.renren.modules.sys.controller;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.renren.common.validator.ValidatorUtils;
import io.renren.modules.sys.service.SysUserService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.sys.entity.AgentShopAdminEntity;
import io.renren.modules.sys.service.AgentShopAdminService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 代理商管理员
 *
 * @author Mark
 * @email sunlightcs@gmail.com
 * @date 2019-10-10 14:17:19
 */
@RestController
@RequestMapping("sys/agentshopadmin")
public class AgentShopAdminController {
    @Autowired
    private AgentShopAdminService agentShopAdminService;
    @Autowired
    private SysUserService sysUserService;
    private Map result = new HashMap();
    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:agentshopadmin:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = agentShopAdminService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("sys:agentshopadmin:info")
    public R info(@PathVariable("id") Integer id){
        AgentShopAdminEntity agentShopAdmin = agentShopAdminService.getById(id);

        return R.ok().put("agentShopAdmin", agentShopAdmin);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:agentshopadmin:save")
    public R save(@RequestBody AgentShopAdminEntity agentShopAdmin){
        agentShopAdminService.save(agentShopAdmin);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:agentshopadmin:update")
    public R update(@RequestBody AgentShopAdminEntity agentShopAdmin){
        ValidatorUtils.validateEntity(agentShopAdmin);
        agentShopAdminService.updateById(agentShopAdmin);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:agentshopadmin:delete")
    public R delete(@RequestBody Integer[] ids){
        agentShopAdminService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    @RequestMapping("getSysUsers")
    public R getSysUsers(@RequestParam Map<String, Object> params) {
        result.clear();
        PageUtils page = sysUserService.queryPage(params);
        List userList = page.getList();
        result.put("data", userList);
        return R.ok(result);
    }

    /**
     * 删除
     */
    @RequestMapping("/deleteById")
    public R deleteById(@RequestBody Integer id){
        agentShopAdminService.removeById(id);

        return R.ok();
    }
}
